package com.gugee.tiktok.web.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.gugee.tiktok.web.model.mysql.Blogger;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.io.Serializable;
import java.util.List;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class BloggerResponse implements Serializable {
    private static final long serialVersionUID = 1L;
    private Long id;
    /**
     * 被关注数
     */
    private int followerCount;

    private long avgViews;

    private long likeCount;

    private long totalFavorited;

    private long avgLikes;

    private long avgReviews;

    private long avgShare;

    private long uid;

    /**
     * o_nickname
     */
    private String nickname;

    private String uniqueId;
    /**
     * o_avatar_300x300
     */
    private String avatar;

    private String avatar168;

    private String signature;

    private Double score;

    private int awemeCount;

    private String region;

    private long lastPubTime;

    private Long collectId;

    private boolean favorite;

    /**
     *企业蓝V认证
     */
    private String enterpriseVerifyReason;
    /**
     *个人蓝V认证
     */
    private String customVerify;
    /**
     *个人主页website
     */
    private String bioUrl;
    /**
     *是否开通购物车
     */
    private Boolean withFusionShopEntry;
    /**
     *youtube账号id
     */
    private String youtubeChannelId;
    /**
     *twitter账号id
     */
    private String twitterId;
    /**
     * instagram账号id
     */
    private String insId;
    /**
     * email
     */
    private String bioEmail;
    /**
     * 播主当日全球排名
     */
    private int globalRanking;

    /**
     * 语言分布比例
     */
    private List<StatisticsData<Double>> languageDistribution;
    /**
     * 国家分布比例
     */
    private List<StatisticsData<Double>> regionDistribution;
    /**
     * 性别比例
     */
    private List<StatisticsData<Double>> genderDistribution;
    /**
     * 年龄比例
     */
    private List<StatisticsData<Double>> ageDistribution;
    // 语言
    private StatisticsData<Double> fansLanguage;
    // 国家
    private StatisticsData<Double> fansRegion;
    // 性别
    private StatisticsData<Double> fansGender;
    // 年龄
    private StatisticsData<Double> fansAge;

    @Mapper(componentModel = "spring")
    public interface BloggerMapper {
        @Mapping(target = "followerCount", source = "OFollowerCount")
        @Mapping(target = "avgViews", source = "OAvgViews")
        @Mapping(target = "avgLikes", source = "OAvgLikes")
        @Mapping(target = "avgReviews", source = "OAvgReviews")
        @Mapping(target = "avgShare", source = "OAvgShare")
        @Mapping(target = "likeCount", source = "OTotalFavorited")
        @Mapping(target = "nickname", source = "ONickname")
        @Mapping(target = "uniqueId", source = "OUniqueId")
        @Mapping(target = "avatar", source = "OAvatar168")
        @Mapping(target = "signature", source = "OSignature")
        @Mapping(target = "score", source = "score")
        @Mapping(target = "awemeCount", source = "OAwemeCount")
        @Mapping(target = "region", source = "ORegion")
        @Mapping(target = "uid", source = "OUid")
        @Mapping(target = "lastPubTime", expression = "java(getTimeStamp(dto))")
        BloggerResponse mapper(Blogger dto);

        List<BloggerResponse> mapper(List<Blogger> dtos);


        default long getTimeStamp(Blogger dto){
            if(null != dto.getLastPubTime()){
                return dto.getLastPubTime().getTime();
            }
            return 0;
        }



    }
}
